import math


class CachedMath:

    def __init__(self):
        self._cache_factorial: tuple[tuple[int], int] = ((0,), 1)
        self._cache_power: tuple[tuple[float, int], int] = ((1, 0), 0)

    def factorial_slow(self, n: int):
        cache = self._cache_factorial
        if n < cache[0][0]:
            result = math.factorial(n)
        else:
            result = cache[1]
            for i in range(cache[0][0] + 1, n + 1):
                result *= i
        self._cache_factorial = ((n,), result)
        return result

    def pow(self, n: float, p: int):
        return n ** p
